const createApp = require('./app')

const server = require('express')()
const renderer = require('vue-server-renderer').createRenderer({
  template: require('fs').readFileSync('./server/index.template.html', 'utf-8')
})

server.get('*', (req, res) => {
  const context = { url: req.url }
  const app = createApp(context)

  renderer.renderToString(app, (err, html) => {
    res.writeHead(200, {'Content-Type': 'text/html;charset=utf-8'});// 设置response编码为utf-8
    if (err) {
      res.status(500).end('Internal Server Error')
      return
    }

    res.end(html)
  })
})

server.listen(8082)
